educational

Banner Rotation Using JavaScript

One of the most welcome "newbie" applications for JavaScript is as a means of banner rotation. While the more experienced Webmaster may shun such an application in favor of much more robust CGI/Perl, PHP, or other suitable technologies, these are often beyond the newbie's grasp (and budget), and likely not possible with most free hosted Web accounts. Here are three good examples of banner rotation using JavaScript:

BANNER ROTATOR #1
This script shows a random banner or other image along with a hyperlink and text description. This script is easily customizable for your page; simply change the linking urls, image urls, and the link names that you wish to display (be sure the order matches) and ensure that the last one of each type does not contain a comma (,) at the end.

<SCRIPT language="JavaScript">
<!-- BANNER ROTATOR #1

var currentdate = 0;
var core = 0;

This "weighted" rotation script not only displays your banners, but also controls how often they appear, allowing you to display a preferred banner over any others!

function initArray() {

this.length = initArray.arguments.length;
for (var i = 0; i < this.length; i++) {
this[i] = initArray.arguments[i];
}
}

link = new initArray(
"https://URL 1/",
"https://URL 2/",
"https://URL 3/"
);

image = new initArray(
"https://IMAGE 1.gif",
"https://IMAGE 2.gif",
"https://IMAGE 3.gif"
);

text = new initArray(
"DESCRIPTION 1",
"DESCRIPTION 2",
"DESCRIPTION 3"
);

var currentdate = new Date();
var core = currentdate.getSeconds() % image.length;
var ranlink = link[core];
var ranimage = image[core];
var rantext = text[core];

document.write('<a href=\"' +ranlink+ '\"><img src=\"'+ranimage+'\" border="0" alt=\"'+rantext+'\"></a>');

// BANNER ROTATOR #1 -->
</SCRIPT>

BANNER ROTATOR #2
This hot script will change banner images on the fly, with no need to reload the page! You can also adjust the amount of time that each banner is shown!

Place the following lines inside of your <HEAD></HEAD> tag:

<SCRIPT language="JavaScript">
<!-- BANNER ROTATOR #2
var mfBanners = [
['https://www.URL 1.com', 'https://BANNER 1.gif'],
['https://www.URL 2.com', 'https://BANNER 2.gif'],
['https://www.URL 3.com', 'https://BANNER 3.gif']
];
var mfIe = false;
if( document.all) {
mfIe = true;
}
var mfBannerIndex = 0;
function mfBannerChange() {
var htmlString = '<a target="_blank" href="'+mfBanners[mfBannerIndex][0]+'"> <img border="0" src="'+mfBanners[mfBannerIndex][1]+'"></a>';
if( mfIe) {
document.all.banner.innerHTML = htmlString;
}
else {
document.layers["banner"].document.open();
document.layers["banner"].document.write( htmlString);
document.layers["banner"].document.close();
}
if(mfBannerIndex < mfBanners.length - 1)
mfBannerIndex++;
else
mfBannerIndex = 0;
}
setInterval("mfBannerChange()", 5000);
// BANNER ROTATOR #2 -->
</SCRIPT>

Now put the following lines inside of your <BODY> code:

<DIV id="banner" style="position:absolute; top:300; left:171;"></DIV>

BANNER ROTATOR #3
This "weighted" rotation script not only displays your banners, but also controls how often they appear, allowing you to display a preferred banner over any others!

Place the following lines inside of your <HEAD></HEAD> tag:

<SCRIPT language="JavaScript">
<!-- BANNER ROTATOR #3
function banner(imgSource,url,alt,chance) {
this.imgSource = imgSource;
this.url = url;
this.alt = alt;
this.chance = chance;
}
function dispBanner() {
with (this) document.write("<A HREF=" + url + "><IMG SRC='" + imgSource + "' WIDTH=468 HEIGHT=60 BORDER=0 ALT='" + alt + "'></A>");
}
banner.prototype.dispBanner = dispBanner;
banners = new Array();
banners[0] = new banner("https://www.BANNER 1.jpg",
"https://www.URL 1.net target='_blank'",
"DESCRIPTION 1",
10);
banners[1] = new banner("https://BANNER 2.gif",
"https://www.URL 2.com target='_blank'",
"DESCRIPTION 2",
30);
banners[2] = new banner("https://BANNER 3.gif",
"https://www.URL 3.com target='_blank'",
"DESCRIPTION 3",
20);

///////////////////////////////////////////////////
// banners[x] = new banner(<banner source image>, // <url to link to when the banner is clicked>, // <alt> // <the chance this banner has in which to be randomly selected>);
// To increase the chance of a banner being randomly selected, increase it's corresponding // 'chance' property relative to the other banners.
///////////////////////////////////////////////////

sum_of_all_chances = 0;
for (i = 0; i < banners.length; i++) {
sum_of_all_chances += banners[i].chance;
}
function randomBanner() {
chance_limit = 0;
randomly_selected_chance = Math.round((sum_of_all_chances - 1) * Math.random()) + 1;
for (i = 0; i < banners.length; i++) {
chance_limit += banners[i].chance;
if (randomly_selected_chance <= chance_limit) {
document.write("<A HREF=" + banners[i].url + "><IMG SRC='" + banners[i].imgSource + "' WIDTH=468 HEIGHT=60 BORDER=0 ALT='" + banners[i].alt + "'></A>");
return banners[i];
break;
}
}
}
// BANNER ROTATOR #3 -->
</SCRIPT>

Hopefully one of these JavaScripts will allow you to maximize your advertising effectiveness by presenting a variety of banners to your site's visitors. Measuring which of several banners produces the best results will alow you to tailor your ad approach to your audience. Good Luck!

Copyright © 2025 Adnet Media. All Rights Reserved. XBIZ is a trademark of Adnet Media.
Reproduction in whole or in part in any form or medium without express written permission is prohibited.

More Articles

opinion

WIA Profile: Lainie Speiser

With her fiery red hair and a laugh that practically hugs you, Lainie Speiser is impossible to miss. Having repped some of adult’s biggest stars during her 30-plus years in the business, the veteran publicist is also a treasure trove of tales dating back to the days when print was king and social media not even a glimmer in the industry’s eye.

Women in Adult ·
opinion

Fighting Back Against AI-Fueled Fake Takedown Notices

The digital landscape is increasingly being shaped by artificial intelligence, and while AI offers immense potential, it’s also being weaponized. One disturbing trend that directly impacts adult businesses is AI-powered “DMCA takedown services” generating a flood of fraudulent Digital Millennium Copyright Act (DMCA) notices.

Corey D. Silverstein ·
opinion

Building Seamless Checkout Flows for High-Risk Merchants

For high-risk merchants such as adult businesses, crypto payments are no longer just a backup plan — they’re fast becoming a first choice. More and more businesses are embracing Bitcoin and other digital currencies for consumer transactions.

Jonathan Corona ·
opinion

What the New SCOTUS Ruling Means for AV Laws and Free Speech

On June 27, 2025, the United States Supreme Court handed down its landmark decision in Free Speech Coalition v. Paxton, upholding Texas’ age verification law in the face of a constitutional challenge and setting a new precedent that bolsters similar laws around the country.

Lawrence G. Walters ·
opinion

What You Need to Know Before Relocating Your Adult Business Abroad

Over the last several months, a noticeable trend has emerged: several of our U.S.-based merchants have decided to “pick up shop” and relocate to European countries. On the surface, this sounds idyllic. I imagine some of my favorite clients sipping coffee or wine at sidewalk cafés, embracing a slower pace of life.

Cathy Beardsley ·
profile

WIA Profile: Salima

When Salima first entered the adult space in her mid-20s, becoming a power player wasn’t even on her radar. She was simply looking to learn. Over the years, however, her instinct for strategy, trust in her teams and commitment to creator-first innovation led her from the trade show floor to the executive suite.

Women in Adult ·
opinion

How the Interstate Obscenity Definition Act Could Impact Adult Businesses

Congress is considering a bill that would change the well-settled definition of obscenity and create extensive new risks for the adult industry. The Interstate Obscenity Definition Act, introduced by Sen. Mike Lee, makes a mockery of the First Amendment and should be roundly rejected.

Lawrence G. Walters ·
opinion

What US Sites Need to Know About UK's Online Safety Act

In a high-risk space like the adult industry, overlooking or ignoring ever-changing rules and regulations can cost you dearly. In the United Kingdom, significant change has now arrived in the form of the Online Safety Act — and failure to comply with its requirements could cost merchants millions of dollars in fines.

Cathy Beardsley ·
opinion

Understanding the MATCH List and How to Avoid Getting Blacklisted

Business is booming, sales are steady and your customer base is growing. Everything seems to be running smoothly — until suddenly, Stripe pulls the plug. With one cold, automated email, your payment processing is shut down. No warning, no explanation.

Jonathan Corona ·
profile

WIA Profile: Leah Koons

If you’ve been to an industry event lately, odds are you’ve heard Leah Koons even before you’ve seen her. As Fansly’s director of marketing, Koons helps steer one of the fastest-growing creator platforms on the web.

Women in Adult ·
Show More